﻿using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting
{
    public class ContextParserFactory : AbstractExpressionParserFactory
    {
        protected readonly IContext Context;

        public ContextParserFactory(IContext context)
        {
            Context = context;
        }

        public override ExpressionParser CreateParser(string expr)
        {
            var cp = new ContextExpressionParser(expr, Context)
                      {
                          ConstantManager = DefaultDependencyManager.Instance.ConstantManager,
                          FunctionManager = Context.GetFunctionManager(),
                          ExpressionParserFactory = this,
                          Context = Context
                      };

            return cp;
        }

        public override ExpressionParser CreateParser(string expr, object context)
        {
            return CreateParser(expr);
        }
    }
}